package cn.dapeng;

public class GenericMethod {

    public static void main(String[] args) {
        Double[] num = {1.11, 2.22, 3.33, 4.44};
        String[] str = {"Hello", "world"};
        Generic01 generic01 = new Generic01();
        Double num1 = generic01.toGeneric01(num);
        String str1 = generic01.toGeneric01(str);


        Generic02<Double> generic02_1 = new Generic02<>();
        Generic02<String> generic02_2 = new Generic02<>();
        Double num2 = generic02_1.toGeneric02(num);
        String str2 = generic02_2.toGeneric02(str);

        generic01.toGeneric01(str);

        Generic03 generic03 = new Generic03();
        generic03.toGeneric03(str);
    }

}

class Generic01 {
    public <T> T toGeneric01(T[] arr) {
        return arr[arr.length - 1];
    }
}

class Generic02<T> {
    public T toGeneric02(T[] arr) {
        return arr[arr.length - 1];
    }
}

class Generic03 {
    public <T> void toGeneric03(T[] arr) {
        T t = arr[arr.length - 1];
    }
}